'use strict';
let init={
    mydb:"manage_tag",
    title:"权限分类",
    edit:"分类编辑",
    add:"分类添加",
    action:"pertag"
}
import Base from './base.js';

export default class extends Base {
  /**
   * index action
   * @return {Promise} []
   */
   async indexAction(){
       let info={
         db:init.mydb,
         page:this.get("page")||1,
         pagesize:this.get("pagesize")||10
       }
       let mydata=await this.model('util').getIndex(info);
       this.assign("itemList",mydata.itemList);
       this.assign('pageData',mydata.pageData);
       this.assign("title",init.title);
       this.assign("action",init.action);
       return this.display();
   }
   async itemAction(){

         let info={
           db:init.mydb,
           edit:init.edit,
           add:init.add,
           id:this.get('id')
         }
         let mydata=await this.model('util').getItem(info);
         this.assign("title",mydata.title);
         this.assign('item',mydata.item);
         console.log(mydata.item);
         this.assign("action",init.action);
         return this.display();
   }

   //编辑或者新增接口
   async saveAction() {
        let info={
          db:init.mydb,
          data:this.post(),
          id:this.post('id')
        }
        let mydata=await this.model('util').doSave(info);
        if(mydata.status===1) return this.success();
  }

  //删除或批量删除接口
  async delsomeAction(){
        let info={
          db:init.mydb,
          arr:this.post('delarr[]')
        }
        let where={id: ["IN", info.arr]};
        let rs=await this.model("admin").deleteRecord(info.db,where);
        if(rs) return this.success();
  }
}
